package com.ccc.scala.base7_collection

object Collection14_Par {

  def main(args: Array[String]): Unit = {
    // 并行
    // Scala为了充分使用多核CPU，
    // 提供了并行集合（有别于前面的串行集合），用于多核环境的并行计算。

    val result1 = (0 to 100).map(x => Thread.currentThread().getName)
    val result2 = (0 to 100).par.map(x => Thread.currentThread().getName)

    println(result1)
    /*
    Vector(main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main, main)
     */

    println(result2)
    /*
    ParVector(scala-execution-context-global-12, scala-execution-context-global-12, scala-execution-context-global-12, scala-execution-context-global-12, scala-execution-context-global-12, scala-execution-context-global-12, scala-execution-context-global-17, scala-execution-context-global-17, scala-execution-context-global-17, scala-execution-context-global-17, scala-execution-context-global-17, scala-execution-context-global-17, scala-execution-context-global-16, scala-execution-context-global-16, scala-execution-context-global-16, scala-execution-context-global-16, scala-execution-context-global-16, scala-execution-context-global-16, scala-execution-context-global-16, scala-execution-context-global-16, scala-execution-context-global-16, scala-execution-context-global-16, scala-execution-context-global-16, scala-execution-context-global-16, scala-execution-context-global-16, scala-execution-context-global-14, scala-execution-context-global-14, scala-execution-context-global-14, scala-execution-context-global-14, scala-execution-context-global-14, scala-execution-context-global-14, scala-execution-context-global-14, scala-execution-context-global-14, scala-execution-context-global-14, scala-execution-context-global-14, scala-execution-context-global-14, scala-execution-context-global-14, scala-execution-context-global-18, scala-execution-context-global-18, scala-execution-context-global-18, scala-execution-context-global-18, scala-execution-context-global-18, scala-execution-context-global-18, scala-execution-context-global-17, scala-execution-context-global-13, scala-execution-context-global-13, scala-execution-context-global-12, scala-execution-context-global-12, scala-execution-context-global-15, scala-execution-context-global-15, scala-execution-context-global-13, scala-execution-context-global-13, scala-execution-context-global-13, scala-execution-context-global-13, scala-execution-context-global-13, scala-execution-context-global-13, scala-execution-context-global-13, scala-execution-context-global-13, scala-execution-context-global-13, scala-execution-context-global-13, scala-execution-context-global-13, scala-execution-context-global-13, scala-execution-context-global-13, scala-execution-context-global-13, scala-execution-context-global-13, scala-execution-context-global-13, scala-execution-context-global-13, scala-execution-context-global-13, scala-execution-context-global-13, scala-execution-context-global-13, scala-execution-context-global-13, scala-execution-context-global-13, scala-execution-context-global-13, scala-execution-context-global-13, scala-execution-context-global-13, scala-execution-context-global-15, scala-execution-context-global-15, scala-execution-context-global-15, scala-execution-context-global-15, scala-execution-context-global-15, scala-execution-context-global-15, scala-execution-context-global-15, scala-execution-context-global-15, scala-execution-context-global-15, scala-execution-context-global-15, scala-execution-context-global-15, scala-execution-context-global-15, scala-execution-context-global-15, scala-execution-context-global-19, scala-execution-context-global-19, scala-execution-context-global-19, scala-execution-context-global-19, scala-execution-context-global-19, scala-execution-context-global-19, scala-execution-context-global-19, scala-execution-context-global-19, scala-execution-context-global-19, scala-execution-context-global-19, scala-execution-context-global-19, scala-execution-context-global-19, scala-execution-context-global-19)
     */
  }

}
